<?php
namespace Core\annotations;

return [
    //类注解
   Bean::class=>function($instance,$container,$self){
        $vars=get_object_vars($self);//获取实例所有属性
        $beanName="";
        if(isset($vars["name"]) && $vars["name"]!=""){
            $beanName=$vars["name"];
        }
        else{
            $arrs=explode("\\",get_class($instance));
            $beanName=end($arrs);
        }

        $container->set($beanName,$instance);
   },

    //属性注解
    Value::class=>function(\ReflectionProperty $prop,$instance,$self){
        $env=parse_ini_file(ROOT_PAHT."/env");
        if(!isset($env[$self->name]) || $self->name=="") return $instance;
        $prop->setValue($instance,$env[$self->name]);
        // var_dump($prop);exit;
        /*
            object(App\controllers\UserController)#29 (1) {
                ["version"]=>
                     string(3) "2.3"
}
        */
        // var_dump($instance);exit;
        /*
            object(ReflectionProperty)#28 (2) {
                ["name"]=>
                    string(7) "version"
                ["class"]=>
                    string(30) "App\controllers\UserController"
            }
        */
        return $instance;
    }

];